﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace SF.WebClient.Controllers
{
    public class DatagridController : BasicController
    {
        public static List<dynamic> datagridJson;

        static DatagridController()
        {
            datagridJson = new List<dynamic>();
            int record = 400; int dt = DateTime.Now.Millisecond;
            for (int i = 0; i < record; i++)
            {
                if (i % 7 == 0)
                {
                    datagridJson.Add(new { ID = (i + 1), AreaName = "地区" + i, Sex1 = ((int)(dt / 100)) + i, Sex2 = 34 + i, TS1 = "T1-" + i, TS2 = "T2-" + i, Others = new List<dynamic> { new { OID = 1 + i.ToString(), OName = "A1-" + i }, new { OID = 2 + i.ToString(), OName = "A2-" + i } } });
                }
                else if (i % 13 == 0)
                {
                    datagridJson.Add(new { ID = (i + 1), AreaName = "地区" + i, Sex1 = ((int)(dt / 100)) + i, Sex2 = 34 + i, TS1 = "T1-" + i, TS2 = "T2-" + i, Obj = new { OID = 3 + i.ToString(), OName = "A3-" + i } });
                }
                else
                {
                    datagridJson.Add(new { ID = (i + 1), AreaName = "地区" + i, Sex1 = ((int)(dt / 100)) + i, Sex2 = 34 + i, TS1 = "T1-" + i, TS2 = "T2-" + i });
                }
            }
        }

        public void ViewDatagridCssSource()
        {
            this.WriteSourceCode("/Scripts/jquery-easyui-extensions/datagrid/jeasyui.extensions.datagrid.css");
        }

        #region findRow 获取指定行

        public ViewResult FindRowDemo()
        {
            return View();
        }

        public PartialViewResult FindRowSource()
        {
            return PartialView();
        }

        public void ViewFindRowSource()
        {
            this.WriteSourceCode("/Scripts/jquery-easyui-extensions/datagrid/jeasyui.extensions.datagrid.findRow.js");
        }

        public PartialViewResult FindRowExplain()
        {
            return PartialView();
        }

        #endregion

        #region getRowData 根据索引获取行

        public ViewResult GetRowDataDemo()
        {
            return View();
        }

        public PartialViewResult GetRowDataSource()
        {
            return PartialView();
        }

        public void ViewGetRowDataSource()
        {
            this.WriteSourceCode("/Scripts/jquery-easyui-extensions/datagrid/jeasyui.extensions.datagrid.getRowData.js");
        }

        public PartialViewResult GetRowDataExplain()
        {
            return PartialView();
        }

        #endregion

        #region rowState 获取行状态

        public ViewResult RowStateDemo()
        {
            return View();
        }

        public PartialViewResult RowStateSource()
        {
            return PartialView();
        }

        public void ViewRowStateSource()
        {
            this.WriteSourceCode("/Scripts/jquery-easyui-extensions/datagrid/jeasyui.extensions.datagrid.rowState.js");
        }

        public PartialViewResult RowStateExplain()
        {
            return PartialView();
        }

        #endregion

        #region deleteRow 删除指定行

        public ViewResult DeleteRowDemo()
        {
            return View();
        }

        public PartialViewResult DeleteRowSource()
        {
            return PartialView();
        }

        public void ViewDeleteRowSource()
        {
            this.WriteSourceCode("/Scripts/jquery-easyui-extensions/datagrid/jeasyui.extensions.datagrid.deleteRow.js");
        }

        public PartialViewResult DeleteRowExplain()
        {
            return PartialView();
        }

        #endregion

        #region moveRow 移动行

        public ViewResult MoveRowDemo()
        {
            return View();
        }

        public PartialViewResult MoveRowSource()
        {
            return PartialView();
        }

        public void ViewMoveRowSource()
        {
            this.WriteSourceCode("/Scripts/jquery-easyui-extensions/datagrid/jeasyui.extensions.datagrid.moveRow.js");
        }

        public PartialViewResult MoveRowExplain()
        {
            return PartialView();
        }

        #endregion

        #region operateRow 操作行

        public ViewResult OperateRowDemo()
        {
            return View();
        }

        public PartialViewResult OperateRowSource()
        {
            return PartialView();
        }

        public void ViewOperateRowSource()
        {
            this.WriteSourceCode("/Scripts/jquery-easyui-extensions/datagrid/jeasyui.extensions.datagrid.operateRow.js");
        }

        public PartialViewResult OperateRowExplain()
        {
            return PartialView();
        }

        #endregion


        #region getColumns 获取列信息

        public ViewResult GetColumnsDemo()
        {
            return View();
        }

        public PartialViewResult GetColumnsSource()
        {
            return PartialView();
        }

        public void ViewGetColumnsSource()
        {
            this.WriteSourceCode("/Scripts/jquery-easyui-extensions/datagrid/jeasyui.extensions.datagrid.getColumnsInfo.js");
        }

        public PartialViewResult GetColumnsExplain()
        {
            return PartialView();
        }

        #endregion

        #region updateColumn 更新列信息

        public ViewResult UpdateColumnDemo()
        {
            return View();
        }

        public PartialViewResult UpdateColumnSource()
        {
            return PartialView();
        }

        public void ViewUpdateColumnSource()
        {
            this.WriteSourceCode("/Scripts/jquery-easyui-extensions/datagrid/jeasyui.extensions.datagrid.updateColumn.js");
        }

        public PartialViewResult UpdateColumnExplain()
        {
            return PartialView();
        }

        #endregion

        #region getColumnData 获取列数据集合

        public ViewResult GetColumnDataDemo()
        {
            return View();
        }

        public PartialViewResult GetColumnDataSource()
        {
            return PartialView();
        }

        public void ViewGetColumnDataSource()
        {
            this.WriteSourceCode("/Scripts/jquery-easyui-extensions/datagrid/jeasyui.extensions.datagrid.getColumnData.js");
        }

        public PartialViewResult GetColumnDataExplain()
        {
            return PartialView();
        }

        #endregion

        #region highlightColumn 高亮指定列

        public ViewResult HighlightColumnDemo()
        {
            return View();
        }

        public PartialViewResult HighlightColumnSource()
        {
            return PartialView();
        }

        public void ViewHighlightColumnSource()
        {
            this.WriteSourceCode("/Scripts/jquery-easyui-extensions/datagrid/jeasyui.extensions.datagrid.highlightColumn.js");
        }

        public PartialViewResult HighlightColumnExplain()
        {
            return PartialView();
        }

        #endregion

        #region operateColumn 操作列

        public ViewResult OperateColumnDemo()
        {
            return View();
        }

        public PartialViewResult OperateColumnSource()
        {
            return PartialView();
        }

        public void ViewOperateColumnSource()
        {
            this.WriteSourceCode("/Scripts/jquery-easyui-extensions/datagrid/jeasyui.extensions.datagrid.operateColumn.js");
        }

        public PartialViewResult OperateColumnExplain()
        {
            return PartialView();
        }

        #endregion



        #region getCellData 获取指定单元格数据

        public ViewResult GetCellDataDemo()
        {
            return View();
        }

        public PartialViewResult GetCellDataSource()
        {
            return PartialView();
        }

        public void ViewGetCellDataSource()
        {
            this.WriteSourceCode("/Scripts/jquery-easyui-extensions/datagrid/jeasyui.extensions.datagrid.getCellData.js");
        }

        public PartialViewResult GetCellDataExplain()
        {
            return PartialView();
        }

        #endregion


        #region getDom 获取行列单元格的Dom对象

        public ViewResult GetDomDemo()
        {
            return View();
        }

        public PartialViewResult GetDomSource()
        {
            return PartialView();
        }

        public void ViewGetDomSource()
        {
            this.WriteSourceCode("/Scripts/jquery-easyui-extensions/datagrid/jeasyui.extensions.datagrid.getDom.js");
        }

        public PartialViewResult GetDomExplain()
        {
            return PartialView();
        }

        #endregion

        #region tooltip 显示行列的提示信息

        public ViewResult TooltipDemo()
        {
            return View();
        }

        public PartialViewResult TooltipSource()
        {
            return PartialView();
        }

        public void ViewTooltipSource()
        {
            this.WriteSourceCode("/Scripts/jquery-easyui-extensions/datagrid/jeasyui.extensions.datagrid.tooltip.js");
        }

        public PartialViewResult TooltipExplain()
        {
            return PartialView();
        }

        #endregion


        #region columnToggle 列显隐

        public ViewResult ColumnToggleDemo()
        {
            return View();
        }

        public PartialViewResult ColumnToggleSource()
        {
            return PartialView();
        }

        public void ViewColumnToggleSource()
        {
            this.WriteSourceCode("/Scripts/jquery-easyui-extensions/datagrid/jeasyui.extensions.datagrid.columnToggle.js");
        }

        public PartialViewResult ColumnToggleExplain()
        {
            return PartialView();
        }

        #endregion

        #region liveSearch 高亮关键词查询

        public ViewResult LiveSearchDemo()
        {
            return View();
        }

        public PartialViewResult LiveSearchSource()
        {
            return PartialView();
        }

        public void ViewLiveSearchSource()
        {
            this.WriteSourceCode("/Scripts/jquery-easyui-extensions/datagrid/jeasyui.extensions.datagrid.liveSearch.js");
        }

        public PartialViewResult LiveSearchExplain()
        {
            return PartialView();
        }

        #endregion

        #region Navigating 键盘导航

        public ViewResult NavigatingDemo()
        {
            return View();
        }

        public PartialViewResult NavigatingSource()
        {
            return PartialView();
        }

        public void ViewNavigatingSource()
        {
            this.WriteSourceCode("/Scripts/jquery-easyui-extensions/datagrid/jeasyui.extensions.datagrid.navigating.js");
        }

        public PartialViewResult NavigatingExplain()
        {
            return PartialView();
        }

        #endregion

        #region GroupSummary 分组汇总

        public ViewResult GroupSummaryDemo(string type = "local")
        {
            if (!new string[] { "local", "remote" }.Contains(type))
            {
                type = "local";
            }
            ViewBag.Type = type;

            return View();
        }

        public PartialViewResult GroupSummarySource()
        {
            return PartialView();
        }

        public void ViewGroupSummarySource()
        {
            this.WriteSourceCode("/Scripts/jquery-easyui-extensions/datagrid/jeasyui.extensions.datagrid.groupSummary.js");
        }

        public PartialViewResult GroupSummaryExplain()
        {
            return PartialView();
        }

        #endregion

        #region 导出到excel

        public ViewResult ExportDemo(string type = "4", bool remote = false)
        {
            if (!new string[] { "1", "2", "3", "4" }.Contains(type)) { type = "4"; }
            ViewBag.InitType = type;
            ViewBag.Remote = remote;

            return View();
        }

        public PartialViewResult ExportSource()
        {
            return PartialView();
        }

        public void ViewExportSource()
        {
            this.WriteSourceCode("/Scripts/jquery-easyui-extensions/datagrid/jeasyui.extensions.datagrid.export.js");
        }

        public PartialViewResult ExportExplain()
        {
            return PartialView();
        }

        public JsonResult GetDataGridJson(int page = 1, int rows = 10)
        {
            var data = datagridJson.AsEnumerable();
            if (page == 0) { return Json(new { total = data.Count(), rows = data }); }

            return Json(new { total = data.Count(), rows = rows > 0 ? data.Skip((page - 1) * rows).Take(rows) : data });
        }

        #endregion





        #region editors 编辑器扩展

        public ViewResult EditorsDemo()
        {
            var model = new DatagridExcelDataModel() { ApplyStaff = "ly001", ApplyStaffName = "落阳", ApplyDepartment = "scb002", ApplyDepartmentName = "市场部", ApplyDate = DateTime.Now };

            return View(model);
        }

        public PartialViewResult EditorsSource()
        {
            return PartialView();
        }

        public void ViewEditorsSource()
        {
            this.WriteSourceCode("/Scripts/jquery-easyui-extensions/datagrid/jeasyui.extensions.datagrid.editors.js");
        }

        public PartialViewResult EditorsExplain()
        {
            return PartialView();
        }

        #endregion

        #region extEdit 仿ext行编辑

        public ViewResult ExtEditDemo()
        {
            var model = new DatagridExcelDataModel() { ApplyStaff = "ly001", ApplyStaffName = "落阳", ApplyDepartment = "scb002", ApplyDepartmentName = "市场部", ApplyDate = DateTime.Now };

            return View(model);
        }

        public PartialViewResult ExtEditSource()
        {
            return PartialView();
        }

        public void ViewExtEditSource()
        {
            this.WriteSourceCode("/Scripts/jquery-easyui-extensions/datagrid/jeasyui.extensions.datagrid.extEdit.js");
        }

        public PartialViewResult ExtEditExplain()
        {
            return PartialView();
        }

        #endregion

        #region 编辑器扩展-回车聚焦

        public ViewResult EditorEnterFocusDemo() 
        {
            return View();
        }

        public PartialViewResult EditorEnterFocusSource()
        {
            return PartialView();
        }

        public void ViewEditorEnterFocusSource()
        {
            this.WriteSourceCode("/Scripts/jquery-easyui-extensions/datagrid/jeasyui.extensions.datagrid.edit.enterFocus.js");
        }

        public PartialViewResult EditorEnterFocusExplain()
        {
            return PartialView();
        }

        #endregion

        #region 编辑器扩展-单元格编辑

        public ViewResult CellEditDemo()
        {
            return View();
        }

        public PartialViewResult CellEditSource()
        {
            return PartialView();
        }

        public void ViewCellEditSource()
        {
            this.WriteSourceCode("/Scripts/jquery-easyui-extensions/datagrid/jeasyui.extensions.datagrid.edit.cellEdit.js");
        }

        public PartialViewResult CellEditExplain()
        {
            return PartialView();
        }

        #endregion

        #region 编辑器扩展-本页自动统计

        public ViewResult AutoCountDemo()
        {
            return View();
        }

        public PartialViewResult AutoCountSource()
        {
            return PartialView();
        }

        public void ViewAutoCountSource()
        {
            this.WriteSourceCode("/Scripts/jquery-easyui-extensions/datagrid/jeasyui.extensions.datagrid.edit.autoCount.js");
        }

        public PartialViewResult AutoCountExplain()
        {
            return PartialView();
        }

        #endregion
    }
}